package org.spring.springboot.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spring.springboot.base.BaseCommon;
import org.spring.springboot.util.ResponseResult;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BaseController extends BaseCommon {
    public Logger logger = LoggerFactory.getLogger(getClass());

    public String updateMsg = "影响了${row}条";

    /**
     * 默认成功
     *
     * @return
     */
    public ResponseResult success() {
        return new ResponseResult();
    }

    /**
     * 默认成功 - 添加返回数据
     *
     * @return
     */
    public ResponseResult success(Object data) {
        return new ResponseResult(data);
    }

    /**
     * 默认成功 - 添加返回数据,并修改返回信息
     *
     * @return
     */
    public ResponseResult success(Object data, String msg) {
        return new ResponseResult(data, ResponseResult.State.SUCCESS.getCode(), msg);
    }

    /**
     * 默认成功 - 修改返回信息
     *
     * @return
     */
    public ResponseResult success(String msg) {
        return new ResponseResult(null, ResponseResult.State.SUCCESS.getCode(), msg);
    }

    /**
     * 默认错误
     *
     * @return
     */
    public ResponseResult error() {
        return new ResponseResult(null, ResponseResult.State.DEFAULT);
    }

    /**
     * 默认错误 - 自定义错误信息
     *
     * @return
     */
    public ResponseResult error(String msg) {
        logger.error(msg);
        return new ResponseResult(null, ResponseResult.State.DEFAULT.getCode(), msg);
    }

    /**
     * 默认错误 - 自定义错误code 和 错误信息
     *
     * @return
     */
    public ResponseResult error(int code, String msg) {
        logger.error(msg);
        return new ResponseResult(null, code, msg);
    }

}
